/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.ces4.produccion.jpa.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.PostLoad;
import javax.persistence.Table;

/**
 *
 * @author usuario
 */
@Entity
@Table(name = "tpdr_perfil")
@NamedQueries({
    @NamedQuery(name = "Perfil.findAll", query = "SELECT p FROM Perfil p")})
public class Perfil implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "NMID", nullable = false)
    private Integer nmid;
    @Basic(optional = false)
    @Column(name = "DSDESCRIPCION", nullable = false, length = 50)
    private String dsdescripcion;
    @ManyToMany(mappedBy = "perfilList", fetch = FetchType.LAZY)
    private List<Usuario> usuarioList;

    public Perfil() {
    }

    public Perfil(Integer nmid) {
        this.nmid = nmid;
    }

    public Perfil(Integer nmid, String dsdescripcion) {
        this.nmid = nmid;
        this.dsdescripcion = dsdescripcion;
    }

    public Integer getNmid() {
        return nmid;
    }

    public void setNmid(Integer nmid) {
        this.nmid = nmid;
    }

    public String getDsdescripcion() {
        return dsdescripcion;
    }

    public void setDsdescripcion(String dsdescripcion) {
        this.dsdescripcion = dsdescripcion;
    }

    public List<Usuario> getUsuarioList() {
        return usuarioList;
    }

    public void setUsuarioList(List<Usuario> usuarioList) {
        this.usuarioList = usuarioList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (nmid != null ? nmid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Perfil)) {
            return false;
        }
        Perfil other = (Perfil) object;
        if ((this.nmid == null && other.nmid != null) || (this.nmid != null && !this.nmid.equals(other.nmid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.com.ces4.produccion.jpa.entities.Perfil[ nmid=" + nmid + " ]";
    }

    @PostLoad
    public void fixIt() {
        this.usuarioList = new ArrayList<Usuario>(this.usuarioList);
    }
}
